package com.hxkj.controller;

import com.alibaba.fastjson.JSONObject;
import com.hxkj.domain.po.LabelExt;
import com.hxkj.domain.po.LabelManagement;
import com.hxkj.domain.po.LabelUsageInfo;
import com.hxkj.domain.vo.LabelManagementVO;
import com.hxkj.service.LabelConfService;
import com.platform.common.domain.result.ResultDataStruct;
import com.platform.common.domain.result.ResultMessageStruct;
import com.platform.common.domain.result.ResultPageStruct;
import com.platform.common.domain.to.PageTo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.List;
import java.util.concurrent.Callable;

@RestController
@RequestMapping(value = "/label")
public class LabelConfController {


    @Autowired
    private LabelConfService labelConfService;

    @RequestMapping(value = "/getLabelList")
    public Callable<ResultPageStruct<LabelManagementVO>> getLabelList(@ModelAttribute LabelManagement labelManagement, @ModelAttribute PageTo pageParam){
        return () -> labelConfService.getLabelList(labelManagement, pageParam);
    }

    @RequestMapping(value = "/getLabelInfo")
    public Callable<LabelManagement> getLabelInfo(@ModelAttribute LabelManagement labelManagement){
        return () -> labelConfService.get(labelManagement);
    }

    /**
     * 新增标签
     * @param jsonObject
     * @return
     */
    @RequestMapping(value = "/save")
    public void save(@RequestBody JSONObject jsonObject) throws Exception{
        labelConfService.save(jsonObject);
    }

    /**
     * 扩展表和用法表的新增修改
     * @param jsonObject
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/editLabelPlus")
    public Callable<ResultMessageStruct> editLabelPlus(@RequestBody JSONObject jsonObject){
        return () -> labelConfService.editLabelPlus(jsonObject);
    }

    /**
     * 扩展表和用法表的删除
     * @param jsonObject
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/deleteLabelPlus")
    public Callable<ResultMessageStruct> deleteLabelPlus(@RequestBody JSONObject jsonObject){
        return () -> labelConfService.deleteLabelPlus(jsonObject);
    }


    /**
     * 修改标签
     * @param jsonObject
     * @return
     */
    @RequestMapping(value = "/modify")
    public void modifyLabel(@RequestBody JSONObject jsonObject) throws Exception{
        labelConfService.modify(jsonObject);
    }

    /**
     * 修改标签
     * @param labelIds
     * @return
     */
    @RequestMapping(value = "/delete")
    public void deleteLabel(String labelIds) throws Exception{
        labelConfService.remove(labelIds);
    }


    /****************************标签扩展表业务处理*************************************/

    /**
     * @Description 获取标签列表
     * @param labelExt
     * @return
     */
    @RequestMapping(value = "/getLabelExtList")
    public Callable<ResultDataStruct<List<LabelExt>>> getLabelExtList(@ModelAttribute LabelExt labelExt){
        return () -> labelConfService.getLabelExt(labelExt);
    }

    /**
     * 新增标签
     * @param labelExt
     * @return
     */
    @RequestMapping(value = "/saveLabelExt")
    public Callable<ResultMessageStruct> saveLabelExt(@ModelAttribute LabelExt labelExt){
        return () -> labelConfService.saveLabelExt(labelExt);
    }

    /**
     * 修改标签
     * @param labelExt
     * @return
     */
    @RequestMapping(value = "/modifyLabelExt")
    public Callable<ResultMessageStruct> modifyLabelExt(@ModelAttribute LabelExt labelExt){
        return () -> labelConfService.modifyLabelExt(labelExt);
    }

    /**
     * 修改标签
     * @param labelExt
     * @return
     */
    @RequestMapping(value = "/deleteLabelExt")
    public Callable<ResultMessageStruct> deleteLabelExt(@ModelAttribute LabelExt labelExt){
        return () -> labelConfService.removeLabelExt(labelExt);
    }


    /****************************标签用法表业务处理*************************************/

    /**
     * @Description 获取标签列表
     * @param labelUsageInfo
     * @return
     */
    @RequestMapping(value = "/getLabelUsageInfoList")
    public Callable<ResultDataStruct<List<LabelUsageInfo>>> getLabelUsageInfoList(@ModelAttribute LabelUsageInfo labelUsageInfo){
        return () -> labelConfService.getLabelUsage(labelUsageInfo);
    }

    /**
     * 新增标签
     * @param labelUsageInfo
     * @return
     */
    @RequestMapping(value = "/saveLabelUsageInfo")
    public Callable<ResultMessageStruct> saveLabelUsageInfo(@ModelAttribute LabelUsageInfo labelUsageInfo){
        return () -> labelConfService.saveLabelUsage(labelUsageInfo);
    }

    /**
     * 修改标签
     * @param labelUsageInfo
     * @return
     */
    @RequestMapping(value = "/modifyLabelUsageInfo")
    public Callable<ResultMessageStruct> modifyLabelUsageInfo(@ModelAttribute LabelUsageInfo labelUsageInfo){
        return () -> labelConfService.modifyLabelUsage(labelUsageInfo);
    }

    /**
     * 修改标签
     * @param labelUsageInfo
     * @return
     */
    @RequestMapping(value = "/deleteLabelUsageInfo")
    public Callable<ResultMessageStruct> deleteLabelUsageInfo(@ModelAttribute LabelUsageInfo labelUsageInfo){
        return () -> labelConfService.removeLabelUsage(labelUsageInfo);
    }
}
